﻿using System;
using System.Collections.Generic;
using CardGamesLibrary.Cards;
using CardGamesLibrary.Cards.Decks;
using CardGamesLibrary.Turns;

namespace CardGamesLibrary.Tables
{
    public abstract class GameTable<TCard> : IGameTable<TCard> 
        where TCard : Card
    {
        protected GameTable(int playerSeats)
        {
            PlayerSeats = playerSeats;
            Seats = new List<TableSeat>(playerSeats);
            for (int i = 0; i < playerSeats; i++)
            {
                Seats.Add(CreateNewSeat());
            }
           
            Dealer = new Dealer<TCard>(this);
           
        }

        public abstract TableSeat CreateNewSeat();
        public abstract Deck<TCard> CreateDeck();
 
        public virtual TableSeat AddPlayer(Player player)
        {
            // todo pick up an existing seat where the player is null
            var tableSeat = Seats.Find(a => a.Player == null);
            tableSeat.Player = player;

            return tableSeat;
        }

        public int PlayerSeats
        {
            get; private set;
        }

        public List<TableSeat> Seats
        {
            get; private set;
        }

        public TableTurn Turn
        {
            get;  set;
        }

        public Dealer<TCard> Dealer
        {
            get; set;
        }
        

     
    }
}
